/**
 *  文件名:BaseActivity.java
 *  修改人:lihangjie
 *  创建时间:2015-8-29 下午10:57:10
 */
package com.sharemob.tinchat.base;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.sharemob.tinchat.R;
import com.sharemob.tinchat.modules.account.ActivityFeedback;
import com.sharemob.tinchat.modules.home.FragmentCenter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * 
 * <一句话功能简述>
 *
 * @author lihangjie
 * version [版本号,2015-8-29 下午10:57:10]
 * @see    [相关类/方法]
 * @since  [产品/模块版本]
 *
 */
public abstract class BaseFragment extends Fragment {
	protected TextView tv_title=null;
    protected void setTitle(String title_name){
    	tv_title=(TextView)this.getActivity().findViewById(R.id.tv_title);
    	tv_title.setText(title_name);
    }
	protected abstract void keyEventOfListView(int position,int id);
	
	protected String getItemFromMap(Map<String,String> map,int _index){
		Iterator<?> iter = map.entrySet().iterator();
		String id=null;
		int index=0;
		while (iter.hasNext()) {  
            Map.Entry<String, String> entry = (Map.Entry<String, String>) iter.next();  
            String key = entry.getKey();  
            String name = entry.getValue(); 
            if(index==_index){
            	id=key;
            	System.out.println(key + "__ " + name);  
            	break;
            }else{
            	index++;
            }
            
		}
		return id;	
	}
	protected ListView getListView(ArrayList<Item> list,int id){
		ListView listView=(ListView)getView().findViewById(id);
		ListAdapter listAdapter=new ListAdapter();
		
		listAdapter.setAdapter(list);
		listView.setAdapter(listAdapter);
		
		listView.setOnItemClickListener(new OnItemClickListener(){
	            public void onItemClick(AdapterView<?> parent, View view, int position,long id)
	            {
	            	keyEventOfListView(position,parent.getId());
	            }
	        });
		return listView;  
	}
	protected NoScrollListview getInitListView(ArrayList<Item> list,int id){
		NoScrollListview listView=(NoScrollListview)getView().findViewById(id);
		ListAdapter listAdapter=new ListAdapter();
		
		listAdapter.setAdapter(list);
		listView.setAdapter(listAdapter);
		
		listView.setOnItemClickListener(new OnItemClickListener(){
	            public void onItemClick(AdapterView<?> parent, View view, int position,long id)
	            {
	            	keyEventOfListView(position,parent.getId());
	            }
	        });
		return listView;  
	}
	
	public void gotoView(Context ctx,Class clazz){
		Intent intent = new Intent(); 
        intent.setClass(ctx,clazz);
        startActivity(intent);
        getActivity().overridePendingTransition(R.anim.activity_open,0);
	}

}
